package main

import (
	"context"
	"github.com/cloudwego/kitex/client"
	"github.com/kitex-contrib/obs-opentelemetry/tracing"
	etcd "github.com/kitex-contrib/registry-etcd"
	"log"
	"myuser/demo/dal"
	"myuser/kitex_gen/demouser"
	"myuser/kitex_gen/demouser/userservice"
)

func Init() {
	dal.Init()
}
func main() {
	//第一个是服务名字，第二个是指定服务端的地址
	Init()                                                        //初始化数据库连接
	r, err := etcd.NewEtcdResolver([]string{"192.168.1.18:2379"}) // r不应重复使用。
	if err != nil {
		log.Fatal(err)
	}
	client, err := userservice.NewClient("userservice",
		client.WithSuite(tracing.NewClientSuite()),
		client.WithResolver(r))
	if err != nil {
		log.Fatal(err)
	}
	//通过client进行调用
	//resp, err := client.CreateUser(context.Background(), &demouser.CreateUserRequest{Username: "wpc", Password: "123456"})
	resp, err := client.CheckUser(context.Background(), &demouser.CheckUserRequest{Username: "wpc", Password: "123456"})
	//resp, err := client.MGetUser(context.Background(), &demouser.MGetUserRequest{UserIds: []int64{11, 12}})
	if err != nil {
		log.Fatal(err)
		return
	}
	log.Println(resp)
}
